package com.wzt.lianfirecontrol.adapter.utils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.wzt.lianfirecontrol.R;
import com.wzt.lianfirecontrol.adapter.BaseRecyclerAdapter;
import com.wzt.lianfirecontrol.bean.recode.BarSelectModel;
import com.wzt.lianfirecontrol.utils.ScreenUtils;

public class BarSelectAdapter extends BaseRecyclerAdapter<BarSelectModel> {

    private Context context;

    public BarSelectAdapter(Context context) {
        this.context = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreate(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_bar_select, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBind(RecyclerView.ViewHolder viewHolder, int RealPosition, BarSelectModel data) {
        setItemData((MyViewHolder)viewHolder, data);
    }

    private class MyViewHolder extends RecyclerView.ViewHolder{
        private TextView tv_title;
        public MyViewHolder(View itemView) {
            super(itemView);
            tv_title = itemView.findViewById(R.id.tv_title);
            itemView.getLayoutParams().width = ScreenUtils.getScreenWidth(context) / getItemCount();
        }
    }

    private void setItemData(MyViewHolder viewHolder, BarSelectModel data) {
        viewHolder.tv_title.setText(data.getTitle());
    }
}
